<?php
declare (strict_types = 1);
/**
 * 素材模型
 */
namespace app\common\model;

class Program extends BaseModel
{
    // 设置当前模型对应的完整数据表名称
    protected $table = 't_pgm_seq';

    public function pgmseqList($where = [], $offset = 0, $length = 20) {
        $field = ['a.pgm_seq_id', 'a.seg_name', 'a.s_time', 'a.e_time', 'a.channel_id','t.channel_name'];

        if($length == 'all'){
          $list = self::field($field)
                  ->alias('a')
                  ->where($where)
                  ->join(['t_channel_info'=>'t'],'t_pgm_seq.channel_id=t.id')
                  ->order(['pgm_seq_id' => 'desc'])
                  ->select();
        }else{
          $list = self::field($field)
                  ->alias('a')
                  ->where($where)
                  ->limit(($offset) * $length, $length)
                  ->join(['t_channel_info'=>'t'],'t_pgm_seq.channel_id=t.id')
                  ->order(['pgm_seq_id' => 'desc'])
                  ->select();
        }
        
        $count = self::where($where)->count('pgm_seq_id');

        foreach ($list as $key => $value) {
            $list[$key]['s_time'] = gmdate('H:i:s', $value['s_time']);
            $list[$key]['e_time'] = gmdate('H:i:s', $value['e_time']);
        }
        return [
            'list'  => $list,
            'total' => $count
        ]; 
    }

    public function pgmseqBt($where) {
      $field = ['*'];

      $list = self::field($field)
                  ->whereRaw($where)
                  ->select();
                  
      return $list;
    }

}
